package com.kuaifawu.lwnlawyerclient.Adapter;

import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.android.gms.internal.gc;
import com.kuaifawu.lwnlawyerclient.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangminglei on 15/2/11.
 */
public class LWNAdapter_growLevel extends BaseExpandableListAdapter {
    Activity activity;
    private List<String> groupArray;
    private List<String> childArray;

    public LWNAdapter_growLevel(Activity a) {
        activity = a;

        groupArray = new ArrayList<String>();
        childArray = new ArrayList<String>();

        groupArray.add("1、什么是积分？如何获取积分？");
        groupArray.add("2、等级获得的标准是什么？");
        groupArray.add("3、等级有什么用？");
        groupArray.add("4、积分能花吗？");

        for (int index = 0; index < groupArray.size(); ++index) {
            childArray.add(String.valueOf(index));
        }
    }

    public Object getChild(int groupPosition, int childPosition) {
        return childArray.get(childPosition);
    }

    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    public int getChildrenCount(int groupPosition) {
        return 1;
    }

    // group method stub
    public Object getGroup(int groupPosition) {
        return groupArray.get(groupPosition);
    }

    public int getGroupCount() {
        return groupArray.size();
    }

    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    public View getGroupView(int groupPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {
        if(convertView == null){
            convertView = View.inflate(activity, R.layout.item_growlevel_f, null);
        }
        TextView parentTextView = (TextView) convertView.findViewById(R.id.gc_levelf_content);
        ImageView parentImageView = (ImageView) convertView.findViewById(R.id.gc_levelf_row);
        ImageView bottomImageView = (ImageView) convertView.findViewById(R.id.gc_levelf_bottom);
        parentTextView.setText(groupArray.get(groupPosition));
        if (isExpanded) {
            parentImageView.setBackgroundResource(R.drawable.gc_level_up);
            bottomImageView.setVisibility(View.GONE);
        } else {
            parentImageView.setBackgroundResource(R.drawable.gc_level_down);
            bottomImageView.setVisibility(View.VISIBLE);
        }
        return convertView;
    }

    public View getChildView(int groupPosition, int childPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {
        if(convertView == null){
            convertView = View.inflate(activity, R.layout.item_growlevel_c, null);
        }
        ImageView content = (ImageView) convertView.findViewById(R.id.gc_levelc_content);
        switch (groupPosition){
            case 0:{
                content.setBackgroundResource(R.drawable.gc_level_z1);
            }break;
            case 1: {
                content.setBackgroundResource(R.drawable.gc_level_z2);
            }
            break;
            case 2: {
                content.setBackgroundResource(R.drawable.gc_level_z3);
            }
            break;
            case 3: {
                content.setBackgroundResource(R.drawable.gc_level_z4);
            }
            break;
            default:{

            }break;
        }

        return convertView;
    }

    // View stub to create Group/Children 's View
//    public TextView getGenericView(String string) {
//        // Layout parameters for the ExpandableListView
//        AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(
//                ViewGroup.LayoutParams.FILL_PARENT, 64);
//        TextView text = new TextView(activity);
//        text.setLayoutParams(layoutParams);
//        // Center the text vertically
//        text.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
//        // Set the text starting position
//        text.setPadding(36, 0, 0, 0);
//        text.setText(string);
//        return text;
//    }

    public boolean hasStableIds() {
        return false;
    }

    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}
